//
//  UIView+Extend.m
//  CedarFinancePH
//
//  Created by lshenrong on 2018/4/2.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "UIView+Extend.h"

@implementation UIView (Extend)

+ (UIView *)lineView{
    UIView *verticalLineView = [[UIView alloc]init];
    verticalLineView.backgroundColor = [UIColor colorWithHexString:@"#c8c8c8"];
    return verticalLineView;
}

- (void)addCornerRadius:(CGSize)radius{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:radius];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}

- (void)addDottedLine{
    /* 初始化一个layer */
    CAShapeLayer *border = [CAShapeLayer layer];
    /* 虚线的颜色 */
    border.strokeColor = kGrayColor.CGColor;
    /* 填充虚线内的颜色 */
    border.fillColor = nil;
    /* 贝塞尔曲线路径 */
    //border.path = [UIBezierPath bezierPathWithRect:CGRectMake(4, 4, view.frame.size.width- 8, view.frame.size.height - 8)].CGPath;
    border.path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height )].CGPath;
    
    /* 虚线宽度 */
    border.lineWidth = 0.7f;
    //border.frame = view.bounds; /* 这个因为给了路径, 而且用的约束给的控件尺寸, 所以没什么效果 */
    /* 官方API注释:The cap style used when stroking the path. Options are `butt', `round'
     * and `square'. Defaults to `butt'. */
    /* 意思是沿路径画帽时的样式 有三种 屁股 ; 圆; 广场 ,我没感觉有啥区别 可以自己试一下*/
    border.lineCap = @"square";
    /* 虚线的每个点长  和 两个点之间的空隙 */
    border.lineDashPattern = @[@3, @2];
    /* 添加到你的控件上 */
    [self.layer addSublayer:border];
}


- (void)addRightTopView:(UIView *)view{
    CedarButton *button = [CedarButton buttonWithImageName:@"Close"];
    button.frame = CGRectMake(self.frame.size.width-10, -15, 30, 30);
    [self addSubview:button];
}

- (void)removeAllChildViews{
    while ([self.subviews lastObject] != nil) {
        [(UIView*)[self.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
    }
}




@end
